<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $model backend\modules\admin\models\admin */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="row">
    <div class="col-lg-12 col-sm-12">
        <div class="card">
            <div class="header">
                <h4 class="title">添加支部管理员</h4>
                <br>
                <a href="<?=Url::toRoute(['manager']); ?>" ><i class="icon-home home-icon"> 返回列表页</i></a>
            </div>
            <div class="content">

                <div class="col-xs-12">
                    <?php
                    $label_class=['class'=>'col-sm-3 control-label no-padding-right'];
                    $form = ActiveForm::begin(
                        [
                            'fieldConfig'=>[
                                'options' => ['enctype' => 'multipart/form-data', 'class' => 'form-horizontal'],
                                'template'=> "<div class=\"form-group\">{label}\n<div class=\"col-sm-5\">{input}</div><div class=\"col-sm-3\">{error}</div></div>",
                                'labelOptions' =>['class' => $label_class],
                            ],
                            'method' => 'post',
                        ]
                    );
                    ?>
                    <div class="form-group">
                       <div class="col-sm-5">
                           <select id="branchs" class="form-control" name="branch_id">
                               <option value="">选择支部</option>
                               <?=$branchs;?>
                           </select>
                       </div>
                        <div class="col-sm-5">
                            <select  id="user-id" class="form-control" name="User[id]">
                                <option value="">请先选择支部</option>
                            </select>
                        </div>
                        <div class="col-sm-3"><div class="help-block"></div>
                        </div>
                    </div>
                    <div class="clearfix">
                        <div class="col-md-offset-3 col-md-11">
                            <?= Html::submitButton('提交', ['class'=>'btn btn-info','name' =>'submit-button']) ?>
                            <?= Html::resetButton('重置', ['class'=>'btn btn-primary','name' =>'reset-button']) ?>
                        </div>
                    </div>
                    <?php ActiveForm::end(); ?>
                    <div class="space-4"></div>

                </div><!-- /.col -->
                <div style="clear:both;"></div>
            </div><!-- content -->
        </div><!-- /.card -->
    </div><!-- /.col-sm-10 -->
</div><!-- /.row -->
<?php $this->beginBlock('js') ?>
    $('#branchs').change(function(){
        var branch_id = $("#branchs").val();
        if(branch_id){
            $.ajax({
            type: "get",
            url: "<?=Url::toRoute(['/admin/branch/getmembers'])?>",
            data:"branch_id="+branch_id,
            success: function(resdata){
                var xqo = eval('(' + resdata + ')');

                if(xqo !=''){
                    var members = '<option value=\'\'>选择成员</option>';
                    for(var i in xqo){
                    members += "<option value=\""+xqo[i].id+"\">"+xqo[i].realname+"</option>";
                    }
                    $("#user-id").html(members);
                }else{
                    $("#user-id").html( '<option value=\'\'>暂无成员</option>');
                }
            }
            });
        }
    });
<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['js'], \yii\web\View::POS_END); ?>